package com.lebang.service.sys;

import com.lebang.domain.AdRecordLog;
import com.lebang.domain.EarnStatusRecord;
import com.lebang.entity.RequestHeaders;
import com.lebang.example.EarnStatusRecordExample;
import com.lebang.mapper.AdRecordLogMapper;
import com.lebang.mapper.LbbMemberMapper;
import com.lebang.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
* earn_status_record
* @Author hwq
* @Date 2020-07-14
*/
@Service
public class EarnStatusRecordService extends BaseService<EarnStatusRecord,Integer, EarnStatusRecordExample>{
    @Autowired
    private LbbMemberMapper memberMapper;
    @Autowired
    private AdRecordLogMapper adRecordLogMapper;

    public void add(RequestHeaders requestHeaders, String sdkKey, String adId,Integer type) {

        AdRecordLog record = new AdRecordLog();
        record.setCreateTime(LocalDateTime.now());
        record.setModifyTime(LocalDateTime.now());
        record.setHasDeleted(0);
        record.setIpAddress(requestHeaders.getIpAddr());
        record.setImei(requestHeaders.getImei());
        record.setAppStore(requestHeaders.getAppStore());
        record.setVersion(requestHeaders.getVersion());
        record.setMemberId(requestHeaders.getUserid());
        record.setSdkKey(sdkKey);
        record.setStatus(type);
        record.setAdId(adId);
        LocalDate date = memberMapper.selectCreaTimeByMemberId(requestHeaders.getUserid()).toLocalDate();
        if (date.equals(LocalDate.now())) {
            record.setIsNewMember(1);
        } else {
            record.setIsNewMember(0);
        }
        adRecordLogMapper.insertSelective(record);
    }
}
